<?php
require("phpQuery-onefile.php");
$fp = fopen("url.txt", 'r');
$cp = fopen("contact.txt", 'a+');
fwrite($cp, "公司名		手机		电话		关键字\n");
while (!feof($fp)) {
	$ali_url = fgets($fp);
	//$ali_url = "http://www.bjstbjgs.com";
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $ali_url);
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$file = curl_exec($ch);
	$file =  mb_convert_encoding($file, "UTF-8", "GBK");
	$key_word_pattern = "/name=\"keywords\"\s+content=\"(.*)\"/u";
	preg_match_all($key_word_pattern, $file, $matches);
	$key_word = $matches[1][0];
	$company_pattern = "/[\x{4e00}-\x{9fa5}]+(集团|公司)/u";
	preg_match_all($company_pattern,$file,$matches);
	$company_name = $matches[0];
	$pattern = "/1(3|5)\d{9}/";
	preg_match_all($pattern, $file, $matches);
	$mobile_num = $matches[0];
	$pattern = "/0\d+-\d{7-8}/";
	preg_match_all($pattern, $file, $matches);
	$tel_num = $matches[0];

	foreach ($company_name as $company){}
	//echo $company;
	if ((strlen($mobile_num[0])>10)||(strlen($tel_num)>8)) {
		fwrite($cp, $company);
		fwrite($cp, "	");
		fwrite($cp, $mobile_num[0]);
		fwrite($cp, "	");
		fwrite($cp, $tel_num[0]);
		fwrite($cp, "	");
		fwrite($cp, $key_word);
		fwrite($cp, "\n");
	}
	curl_close($ch);
}

fclose($fp);
fclose($cp);
?>